/*
 * @Author: wangming
 * @Date: 2020-09-16 15:40:37
 * @LastEditors: wangming
 * @LastEditTime: 2022-03-28 15:35:41
 * @Description: file content
 */
var moment = require("moment");

export const dateLimitTypeList = [{
    label: "本月",
    value: "1",
    maxDate: moment().endOf("month").format("YYYY-MM-DD"),
    minDate: moment().startOf("month").add(-1, "days").format("YYYY-MM-DD"),
  },
  {
    label: "本月及前后一个月",
    value: "2",
    maxDate: moment().add(1, "months").endOf("month").format("YYYY-MM-DD"),
    minDate: moment()
      .add(-1, "months")
      .startOf("month")
      .add(-1, "days")
      .format("YYYY-MM-DD"),
  },
  {
    label: "本月及前后两个月",
    value: "3",
    maxDate: moment().add(2, "months").endOf("month").format("YYYY-MM-DD"),
    minDate: moment()
      .add(-2, "months")
      .startOf("month")
      .add(-1, "days")
      .format("YYYY-MM-DD"),
  },
  {
    label: "本月及前后三个月",
    value: "4",
    maxDate: moment().add(3, "months").endOf("month").format("YYYY-MM-DD"),
    minDate: moment()
      .add(-3, "months")
      .startOf("month")
      .add(-1, "days")
      .format("YYYY-MM-DD"),
  },
  {
    label: "本月及前后半年",
    value: "5",
    maxDate: moment().add(6, "months").endOf("month").format("YYYY-MM-DD"),
    minDate: moment()
      .add(-6, "months")
      .startOf("month")
      .add(-1, "days")
      .format("YYYY-MM-DD"),
  },
  {
    label: "本月及后半年",
    value: "6",
    maxDate: moment().add(6, "months").endOf("month").format("YYYY-MM-DD"),
    minDate: moment().startOf("month").add(-1, "days").format("YYYY-MM-DD"),
  },
  {
    label: "本月及前后一年",
    value: "7",
    maxDate: moment().add(12, "months").endOf("month").format("YYYY-MM-DD"),
    minDate: moment()
      .add(-12, "months")
      .startOf("month")
      .add(-1, "days")
      .format("YYYY-MM-DD"),
  },
  {
    label: "当日及以后",
    value: "8",
    maxDate: '',
    minDate: moment().add(-1, "days"),
  },
  {
    label: "当日及以前",
    value: "9",
    maxDate: moment(),
    minDate: '',
  },
  {
    value: "",
    label: "不限制",
    maxDate: "",
    minDate: "",
  },
];

export const dateConfig = [{
    format: "YYYY",
    type: "year",
    label: "年",
    placeholder: "请选择日期",
  },
  {
    format: "YYYY-MM",
    type: "month",
    label: "年-月",
    placeholder: "请选择日期",
  },

  {
    format: "YYYY-MM-DD",
    label: "年-月-日",
    type: "date",
    placeholder: "请选择日期",
  },
  {
    format: "YYYY-MM-DD HH:mm",
    type: "datetime",
    label: "年-月-日 时:分",
    placeholder: "请选择日期及时间",
  },
  {
    format: "YYYY-MM-DD HH:mm:ss",
    type: "datetime",
    label: "年-月-日 时:分:秒",
    placeholder: "请选择日期及时间",
  },

];

export const dateMomentConfig = [{
    format: "YYYY",
    type: "year",
  },
  {
    format: "YYYY-MM",
    type: "month",
  },

  {
    format: "YYYY-MM-DD",
    type: "day",
  },
  {
    format: "YYYY-MM-DD HH:mm",
    type: "datetime",
  },
  {
    format: "YYYY-MM-DD HH:mm:ss",
    type: "datetimeAll",
  },

];

// date 时间戳 
// type dateConfig对应type 
// flag ge/le
export function transformDate(date, type, flag) {
  console.log(date, type, flag)
  let dateTime = null
  if (date) {
    if (["year", "month", 'day'].includes(type)) {
      dateTime = flag === 'ge' ?
        moment(date).startOf(type).valueOf() :
        moment(date).endOf(type).valueOf()
    } else if (type === 'datetime') {
      const num = flag === 'ge' ? 0 : 59
      dateTime = moment(date).set('seconds', num).valueOf()
    } else if (type === 'datetimeAll') {
      dateTime = date
    }
  } else if (date === '') {
    if (["year", "month", 'day'].includes(type)) {
      dateTime = flag === 'ge' ?
        moment().startOf(type).valueOf() :
        moment().endOf(type).valueOf()
    } else if (type === 'datetime') {
      const num = flag === 'ge' ? 0 : 59
      dateTime = moment().set('seconds', num).valueOf()
    } else if (type === 'datetimeAll') {
      dateTime = moment()
    }
  }
  return dateTime
}